package com.Prot2.Logger;

import com.Prot2.Globals;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;

public class LightWorker {
	
	private SensorManager mSensorManager;
	private float lux;
	
	public LightWorker(Context c){
    	mSensorManager= (SensorManager) c.getSystemService(Context.SENSOR_SERVICE);
    	mSensorManager.registerListener(mLightListener, mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT),Globals.samplingRate*1000);

	}
	
	private SensorEventListener mLightListener = new SensorEventListener() {

		@Override
		public void onAccuracyChanged(Sensor arg0, int arg1) {
			// TODO Auto-generated method stub
		}

		@Override
		public void onSensorChanged(SensorEvent event) {
			if(event.sensor.getType() == Sensor.TYPE_LIGHT){
				lux = event.values[0];
			}
		}
		
	};
	
	public float getLux(){
		return lux;
	}

	public String getRead(String DELIMITER){
		return ""+lux;
	}
	
	public void stop(){
		mSensorManager.unregisterListener(mLightListener);
	}
	
}
